//
//  ShopInfoViewController.m
//  NewProject
//
//  Created by 王嘉琪 on 2017/6/13.
//  Copyright © 2017年 李航飞. All rights reserved.
//

#import "ShopInfoViewController.h"
@interface ShopInfoViewController ()<UIScrollViewDelegate>
@property (nonatomic,strong) UIImageView  *firstBigImg;
@property (nonatomic,strong) UILabel  *name;
@property (nonatomic,strong) UILabel  *price;
@property (nonatomic,strong) UILabel  *xiangQingName;
@property (nonatomic,strong) UILabel  *XiangQingSize;
@property (nonatomic,strong) UIScrollView  *scrollView;
@property (nonatomic,strong) UILabel *numLabel;
@property (nonatomic,strong) UIImageView *detailImageView;
@property (nonatomic,strong) NSDictionary *netDictionary;
@end

@implementation ShopInfoViewController
- (NSDictionary *)netDictionary{
    if (!_netDictionary) {
        _netDictionary = [[NSDictionary alloc]init];
    }
    return _netDictionary;
}

- (void)httpGetData{
    [[MyNetWorking sharedManager]GET_PATH:@"g=portal&m=goods&a=goods&gid=1&sid=1" success:^(id responseObject) {
        self.netDictionary = responseObject[0];
        [self refreshData];
        NSLog(@"%@",self.netDictionary);
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden=NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self httpGetData];
    
    self.title=@"商品详情";
    self.view.backgroundColor=[UIColor whiteColor];
    
    UIView *topView = [[UIView alloc]init];
    topView.backgroundColor = RGB0X(0xF8F9F6);
    topView.frame = CGRectMake(0, 0, WIDTH, 8/WIDTH_6_SCALE);
    [self.view addSubview:topView];
    
    [self setUpView];
    // Do any additional setup after loading the view.
}

- (void)refreshData{
    _name.text=self.netDictionary[@"name"];
    [_firstBigImg sd_setImageWithURL:[NSURL URLWithString:SF(@"%@%@",IMAGEURL,self.netDictionary[@"icon"])] placeholderImage:[UIImage imageNamed:@""]];
    [_detailImageView sd_setImageWithURL:[NSURL URLWithString:SF(@"%@%@",IMAGEURL,self.netDictionary[@"details"])] placeholderImage:[UIImage imageNamed:@""]];
    _xiangQingName.text = self.netDictionary[@"level"];
    _price.text = self.netDictionary[@"price"];
}

- (void)setUpView{
    UIScrollView*scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 8/WIDTH_6_SCALE, self.view.frame.size.width, self.view.frame.size.height-64-66/WIDTH_6_SCALE)];
    _scrollView=scrollView;
//    scrollView.contentSize=CGSizeMake(self.view.frame.size.width, self.view.frame.size.height+1000);
    scrollView.bounces=NO;
    scrollView.delegate=self;
    [self.view addSubview:scrollView];
    [scrollView setShowsVerticalScrollIndicator:NO];
    
    _firstBigImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.width-45*kScrenWidth*2)];
    _firstBigImg.image=[UIImage imageNamed:@"商品"];
    [_scrollView addSubview:_firstBigImg];
    
    _name =[[UILabel alloc] initWithFrame:CGRectMake(0, _firstBigImg.frame.size.height+_firstBigImg.frame.origin.y+10, self.view.frame.size.width, 35*kScrenHidth)];
    _name.text=@"商品名称";
    _name.textAlignment = NSTextAlignmentCenter;
    [_scrollView addSubview:_name];
    
    _price=[[UILabel alloc] initWithFrame:CGRectMake(0, _name.frame.size.height+_name.frame.origin.y+5, self.view.frame.size.width, 30*kScrenHidth)];
    _price.text=@"￥7";
    _price.font=[UIFont systemFontOfSize:14];
    _price.textColor=RGB0X(0xFF7E02);
    _price.textAlignment = NSTextAlignmentCenter;
    [_scrollView addSubview:_price];
    
    UILabel *kongLab=[[UILabel alloc] initWithFrame:CGRectMake(0, _price.frame.size.height+_price.frame.origin.y+20*kScrenHidth, WIDTH, 5*kScrenHidth)];
    kongLab.backgroundColor=LINE_COLOE_245;
    [_scrollView addSubview:kongLab];
    
//    UIImageView *xiangQingImg=[[UIImageView alloc] initWithFrame:CGRectMake(90*kScrenWidth, kongLab.frame.size.height+kongLab.frame.origin.y+12*kScrenHidth, WIDTH-2*90*kScrenWidth, 25*kScrenHidth)];
//    [_scrollView addSubview:xiangQingImg];
//    xiangQingImg.backgroundColor=[UIColor yellowColor];
    UIImageView *leftYellowImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"左黄线"]];
    leftYellowImage.frame = CGRectMake(90/WIDTH_6_SCALE, kongLab.frame.size.height+kongLab.frame.origin.y+23*kScrenHidth, 56/WIDTH_6_SCALE, 1/WIDTH_6_SCALE);
    [_scrollView addSubview:leftYellowImage];
    
    UILabel *middleYellowLabel = [[UILabel alloc]init];
    middleYellowLabel.frame = CGRectMake(159/WIDTH_6_SCALE, kongLab.frame.size.height+kongLab.frame.origin.y+15*kScrenHidth, 70/WIDTH_6_SCALE, 15/WIDTH_6_SCALE);
    middleYellowLabel.font = FONT(15);
    middleYellowLabel.text = @"商品详情";
    middleYellowLabel.textColor = RGB0X(0xFFD700);
    [_scrollView addSubview:middleYellowLabel];
    
    UIImageView *rightYellowImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"右黄线"]];
    rightYellowImage.frame = CGRectMake(229/WIDTH_6_SCALE, kongLab.frame.size.height+kongLab.frame.origin.y+23*kScrenHidth, 56/WIDTH_6_SCALE, 1/WIDTH_6_SCALE);
    [_scrollView addSubview:rightYellowImage];
    
    UILabel *xiangQingName=[[UILabel alloc] initWithFrame:CGRectMake(15*kScrenWidth, 440*kScrenHidth, 60*kScrenWidth, 20*kScrenHidth)];
    xiangQingName.text=@"品       牌";
    xiangQingName.font=[UIFont systemFontOfSize:14];
    [_scrollView addSubview:xiangQingName];
    
    _xiangQingName=[[UILabel alloc] initWithFrame:CGRectMake(xiangQingName.frame.size.width+xiangQingName.frame.origin.x+10*kScrenWidth, xiangQingName.frame.origin.y, WIDTH-(xiangQingName.frame.size.width+xiangQingName.frame.origin.x+10*kScrenWidth), 20*kScrenHidth)];
    _xiangQingName.text=@"西瓜";
    _xiangQingName.font=[UIFont systemFontOfSize:14];
    [_scrollView addSubview:_xiangQingName];
    
    UILabel *xiangQingSize=[[UILabel alloc] initWithFrame:CGRectMake(15*kScrenWidth, xiangQingName.frame.size.height+xiangQingName.frame.origin.y+20*kScrenHidth, 60*kScrenWidth, 20*kScrenHidth)];
    xiangQingSize.text=@"产品规格";
    xiangQingSize.font=[UIFont systemFontOfSize:14];
    [_scrollView addSubview:xiangQingSize];
    
    _XiangQingSize=[[UILabel alloc] initWithFrame:CGRectMake(xiangQingSize.frame.size.width+xiangQingSize.frame.origin.x+10*kScrenWidth, xiangQingSize.frame.origin.y, WIDTH-(xiangQingSize.frame.size.width+xiangQingSize.frame.origin.x+10*kScrenWidth), 20*kScrenHidth)];
    _XiangQingSize.text=@"6kg";
    _XiangQingSize.font=[UIFont systemFontOfSize:14];
    [_scrollView addSubview:_XiangQingSize];
    
    
    UILabel *kongLab2=[[UILabel alloc] initWithFrame:CGRectMake(0, _XiangQingSize.frame.size.height+_XiangQingSize.frame.origin.y+20*kScrenHidth, WIDTH, 5*kScrenHidth)];
    kongLab2.backgroundColor=LINE_COLOE_245;
    [_scrollView addSubview:kongLab2];
    
//    UIImageView *tuWenImg=[[UIImageView alloc] initWithFrame:CGRectMake(90*kScrenWidth, kongLab2.frame.size.height+kongLab2.frame.origin.y+12*kScrenHidth, WIDTH-2*90*kScrenWidth, 25*kScrenHidth)];
//    [_scrollView addSubview:tuWenImg];
//    tuWenImg.backgroundColor=[UIColor blackColor];
    
    UIImageView *leftBlackImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"左黑线"]];
    leftBlackImage.frame = CGRectMake(90/WIDTH_6_SCALE, kongLab2.frame.size.height+kongLab2.frame.origin.y+23*kScrenHidth, 56/WIDTH_6_SCALE, 1/WIDTH_6_SCALE);
    [_scrollView addSubview:leftBlackImage];
    
    UILabel *middleBlackLabel = [[UILabel alloc]init];
    middleBlackLabel.frame = CGRectMake(159/WIDTH_6_SCALE, kongLab2.frame.size.height+kongLab2.frame.origin.y+15*kScrenHidth, 70/WIDTH_6_SCALE, 15/WIDTH_6_SCALE);
    middleBlackLabel.font = FONT(15);
    middleBlackLabel.text = @"图文详情";
    middleBlackLabel.textColor = [UIColor blackColor];
    [_scrollView addSubview:middleBlackLabel];
    
    UIImageView *rightBlackImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"右黑线"]];
    rightBlackImage.frame = CGRectMake(229/WIDTH_6_SCALE, kongLab2.frame.size.height+kongLab2.frame.origin.y+23*kScrenHidth, 56/WIDTH_6_SCALE, 1/WIDTH_6_SCALE);
    [_scrollView addSubview:rightBlackImage];
    
    _detailImageView=[[UIImageView alloc] init];
//                      WithFrame:CGRectMake(0, middleBlackLabel.frame.size.height+middleBlackLabel.frame.origin.y+30*kScrenHidth, WIDTH, 1000*kScrenHidth)];
    [_detailImageView setImage:[UIImage imageNamed:@"000"]];
//    _detailImageView.contentMode = UIViewContentModeScaleAspectFill;
//    _detailImageView.autoresizingMask = UIViewAutoresizingFlexibleHeight;
//    _detailImageView.clipsToBounds  = YES;
    [_scrollView addSubview:_detailImageView];
    
    [_detailImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.mas_left);
        make.right.equalTo(self.view.mas_right);
        make.top.equalTo(middleBlackLabel.mas_bottom).offset(30/WIDTH_6_SCALE);
    }];
    [self.view layoutIfNeeded];
    _scrollView.contentSize=CGSizeMake(self.view.frame.size.width, _detailImageView.frame.size.height+_detailImageView.frame.origin.y);
    
    
    UIView *diView=[[UIView alloc] initWithFrame:CGRectMake(0, HIGHT-58*kScrenHidth-64, WIDTH, 58*kScrenHidth)];
    [self.view addSubview:diView];
    
    UIButton *shouButton = [UIButton buttonWithType:UIButtonTypeCustom];
    shouButton.alpha = 0;
    shouButton.frame = CGRectMake(30*kScrenWidth, 6*kScrenHidth, 40*kScrenHidth, 30*kScrenHidth);
    [diView addSubview:shouButton];
    
    UIImageView *shouChang=[[UIImageView alloc] initWithFrame:CGRectMake(30*kScrenWidth, 6*kScrenHidth, 25*kScrenHidth, 25*kScrenHidth)];
    [shouChang setImage:[UIImage imageNamed:@"shou"]];
    [diView addSubview:shouChang];
    
    UILabel *shouChangLab=[[UILabel alloc] initWithFrame:CGRectMake(28*kScrenWidth, 31*kScrenHidth, 40*kScrenWidth, 25*kScrenHidth)];
    shouChangLab.text=@"收藏";
    shouChangLab.font=[UIFont systemFontOfSize:14];
    [diView addSubview:shouChangLab];
    
    UIButton *carButton = [UIButton buttonWithType:UIButtonTypeCustom];
    carButton.alpha = 0;
    carButton.frame = CGRectMake(30*kScrenWidth+shouChang.frame.size.width+shouChang.frame.origin.x, 6*kScrenHidth, 40*kScrenHidth, 30*kScrenHidth);
    [diView addSubview:carButton];

    UIImageView *carImg=[[UIImageView alloc] initWithFrame:CGRectMake(35*kScrenWidth+shouChang.frame.size.width+shouChang.frame.origin.x, 6*kScrenHidth, 30*kScrenHidth, 25*kScrenHidth)];
    [carImg setImage:[UIImage imageNamed:@"che"]];
    [diView addSubview:carImg];
    
    UILabel *carLab=[[UILabel alloc] initWithFrame:CGRectMake(33*kScrenWidth+shouChang.frame.size.width+shouChang.frame.origin.x, 31*kScrenHidth, 45*kScrenWidth, 25*kScrenHidth)];
    carLab.text=@"购物车";
    carLab.font=[UIFont systemFontOfSize:14];
    [diView addSubview:carLab];
    
    UIView *diRightView=[[UIView alloc] initWithFrame:CGRectMake(150*kScrenWidth, 0, 225*kScrenWidth, 58*kScrenHidth)];
    diRightView.backgroundColor=ALL_COLOR;
    [diView addSubview:diRightView];
    
//    UILabel *addShangPin=[[UILabel alloc] initWithFrame:CGRectMake(30*kScrenWidth, 20*kScrenHidth, 90*kScrenWidth, 10*kScrenHidth)];
    UILabel *addLabel = [[UILabel alloc]init];
    addLabel.font = FONT(15);
    addLabel.text = @"添加商品";
    [diRightView addSubview:addLabel];
    
    [addLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(diRightView.mas_left).offset(30/WIDTH_6_SCALE);
        make.centerY.equalTo(diRightView.mas_centerY);
    }];
    
    UIButton *minusButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [minusButton setImage:[UIImage imageNamed:@"减"] forState:UIControlStateNormal];
    [minusButton addTarget:self action:@selector(minusButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [diRightView addSubview:minusButton];
    
    UIButton *addButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [addButton setImage:[UIImage imageNamed:@"加"] forState:UIControlStateNormal];
    [addButton addTarget:self action:@selector(addButtonClick) forControlEvents:UIControlEventTouchUpInside];
    [diRightView addSubview:addButton];

    _numLabel = [[UILabel alloc]init];
    _numLabel.font = FONT(15);
    _numLabel.textColor = RGB0X(0x333333);
    _numLabel.text = @"1";
    _numLabel.textAlignment = NSTextAlignmentCenter;
    [diRightView addSubview:_numLabel];

    [addButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(diRightView.mas_right).offset(-25/WIDTH_6_SCALE);
        make.centerY.equalTo(diRightView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(25/WIDTH_6_SCALE, 25/WIDTH_6_SCALE));
    }];
    [minusButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(addButton.mas_left).offset(-30/WIDTH_6_SCALE);
        make.centerY.equalTo(diRightView.mas_centerY);
        make.size.mas_equalTo(CGSizeMake(25/WIDTH_6_SCALE, 25/WIDTH_6_SCALE));
    }];
    [_numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(minusButton.mas_left);
        make.right.equalTo(addButton.mas_right);
        make.centerY.equalTo(diRightView.mas_centerY);
    }];
}

- (void)minusButtonClick{
    NSInteger lastNum = [_numLabel.text integerValue];
    if (lastNum==1) {
        
    }else{
        lastNum--;
    }
    _numLabel.text = SF(@"%ld",lastNum);
}

- (void)addButtonClick{
    NSInteger lastNum = [_numLabel.text integerValue];
    lastNum++;
    _numLabel.text = SF(@"%ld",lastNum);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
